home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_Install3.adf / piarc.LZH / rgbxr.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-29  |  6KB  |  234 lines

  1. /*
  2.  * rgbxr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: January 17, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate rgbxr.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   /*
  42.    * This code attempts to read a file called "picmdpath" from REXX:
  43.    * If it can't find it, the script will assume that the commands
  44.    * associated with this PI Module are in "c:". If the file exists,
  45.    * the script will look in the path that is specified in the file.
  46.    * If you create this file, you MUST put a complete, correct path
  47.    * in it; if the commands are in a sub-directory, you have to put
  48.    * the trailing slash on the path (like, device:dir/).
  49.    * 
  50.    */
  51.   cmdpath = 'c:';
  52.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  53.     do
  54.       cmdpath = readln(fhandle);
  55.       call close(fhandle);  /* close the file    */
  56.     end
  57.  
  58. options;
  59. address;
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',rgbxpath) = 1 then do
  64.     prevpath = getclip(rgbxpath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'current';
  70.   bufdata = result; /* get name of buffer, if there is one */
  71.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  72.   if bname ~= '<none>' then do
  73.     bufname = bname;
  74.     end;
  75.   'filerequest "'||prevpath||'","'||bufname||'","","Load RGBX"';
  76.   rgbxfile = result;
  77.   options;
  78.  
  79.   if rgbxfile = 'FR_CANCELLED' then do
  80.     address(prtnme);
  81.     'imtofront';
  82.     exit 0;
  83.     end;
  84.  
  85.   rgbxfile = expandfilename(rgbxfile);
  86.   thispath = gimmepath(rgbxfile);
  87.   call setclip(rgbxpath,thispath);
  88.  
  89.   address command cmdpath||'RGBXRD c "'||rgbxfile||'"';
  90.   if rc ~= 0 then do
  91.     address(prtnme);
  92.     'message "Cannot read '||rgbxfile||'"';
  93.     exit 0; /* this is not a proper rgbx file */
  94.     end;
  95.  
  96.   call open(fhandle,'ram:IP_RGBXRD.tmp','read');      /* open the file */
  97.   rstring = readln(fhandle);
  98.   call close(fhandle);                     /* close the file    */
  99.   
  100.   address command 'c:delete >nil: ram:IP_RGBXRD.tmp';
  101.   
  102.   parse var rstring width '/' height
  103.  
  104.   if height < 0 then do
  105.     'message "Bad Height: '||height||'"';
  106.     exit 0;
  107.     end;
  108.  
  109.   if height > 32767 then do
  110.     'message "Bad Height: '||height||'"';
  111.     exit 0;
  112.     end;
  113.  
  114.   if width < 0 then do
  115.     'message "Bad Width: '||width||'"';
  116.     exit 0;
  117.     end;
  118.  
  119.   if width > 32767 then do
  120.     'message "Bad Width: '||width||'"';
  121.     exit 0;
  122.     end;
  123.  
  124.   address(prtnme);
  125.   
  126.   'imtofront'; /* show user the IM screen */
  127.   /* is there already a primary buffer??? */
  128.   options results;
  129.   'current';
  130.   bufdata = result;
  131.   options;
  132.  
  133.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  134.   if bname ~= '<none>' then do
  135.     address(prtnme);
  136.   options results;
  137.   'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  138.   prefs = result;
  139.   options;
  140.   address;
  141.   if prefs = 0 then do
  142.     address(prtnme);
  143.     'killbuff '||bnum; /* this kills the Primary Buffer */
  144.     address;
  145.     end;
  146.   end;
  147.  
  148.   /* New buffer is created at current resolution */
  149.   address(prtnme);
  150.   'autoredraw 0';
  151.   options results;
  152.   'newbuf '||width||' '||height;
  153.   if rc ~= 0 then do
  154.     "message Can't allocate buffer!";
  155.     'autoredraw 1';
  156.     exit 0
  157.     end
  158.   bnum = result;
  159.   options;
  160.   'newcurrent '||bnum;
  161.   'rename '||bnum||' 'gxname;
  162.   'autoredraw 1';
  163.   address;
  164.  
  165.   address(prtnme);
  166.   options results;
  167.   'jackin';
  168.   jackadr = result;
  169.   options;
  170.  
  171.   'wbtofront';
  172.   'lockimage '||bnum;
  173.   address command cmdpath||'RGBXRD d'||jackadr||' "'||rgbxfile||'"';
  174.   'unlockimage '||bnum;
  175.  
  176.   address(prtnme);
  177.   'imtofront';
  178.   'redraw';
  179.   address;
  180.  
  181.   exit 0;
  182.  
  183. /*
  184.  * gimmepath
  185.  *
  186.  * This takes the provided argument and sucks the path out of it, then
  187.  * returns that path to the caller, sans file name.
  188.  */
  189. gimmepath:
  190.   arg fullnamegx;
  191.     tempgx = reverse(fullnamegx);
  192.     lengx = length(fullnamegx);   /* get length of string */
  193.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  194.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  195.     seploc = 0; /* assumes current dir, no path supplied */
  196.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  197.       seploc = (lengx - slashdex)+1;
  198.       end;
  199.     else do
  200.       if colondex ~= 0 then do /* we assume we are on a device */
  201.         seploc = (lengx - colondex)+1;
  202.         end;
  203.       end;
  204.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  205.   gxpath = left(fullnamegx,seploc);
  206.   return(gxpath);
  207.  
  208. /*
  209.  * Since this script can't be expected to know where the CD of the user
  210.  * is when this cmd is invoked, we have to check the path the user
  211.  * provides - if it's not specified right from a root, then we have
  212.  * to make it a complete specification from the root.
  213.  */
  214. expandfilename:
  215.   parse arg jfile;
  216.   if index(jfile,':') = 0 then do
  217.     curdir = pragma(D);
  218.     if right(curdir,1) ~= ':' then do
  219.       if right(curdir,1) ~= '/' then do
  220.         if curdir ~= '' then do
  221.           curdir = curdir || '/';
  222.           end;
  223.         end;
  224.       end;
  225.     jfile = curdir||jfile;
  226.     end;
  227.   return(jfile);
  228.  
  229. rvalue:
  230.   wordnum = c2d(readch(fhandle,1)) * 256;
  231.   wordnum = wordnum + c2d(readch(fhandle,1));
  232.   return wordnum;
  233.  
  234.